// components/custom-navigation-bar/custom-navigation-bar.js
Component({
  // Component 组件的属性定义
  properties: {
    // 这里可以定义组件接收的外部属性，比如title
    nowWeek: {
      type: Number,  // 指定数据类型（String | Number | Boolean | Object | Array 等）
      value: 1,      // 默认值（如果父组件没有传值）
      observer: function(newVal, oldVal) {
        // 监听 nowWeek 变化（可选）
        // console.log('nowWeek 变化:', newVal);
      }
    }
  },
  
  // Component 组件的初始数据
  data: {
    nowWeek:1,     //当前周
    tatolWeek:20,  //一共周数
    showSwitchWeek:false, //显示弹窗开关变量
    statusBarHeight: 0,
    navBarHeight: 0,
    showBack: false,
  },

  // Component 组件的生命周期函数（正确位置！）
  lifetimes: {
    attached() { // 当组件被添加到页面时自动执行
      const systemInfo = wx.getSystemInfoSync();
      let statusBarHeight = systemInfo.statusBarHeight;
      const capsule = wx.getMenuButtonBoundingClientRect();
      let navBarHeight = (capsule.bottom - statusBarHeight) + (capsule.top - statusBarHeight) + statusBarHeight;
      // 判断是否显示返回按钮：获取当前页面栈
      const pages = getCurrentPages();
      const showBack = pages.length > 1;
      let p = statusBarHeight;
      navBarHeight = navBarHeight + p + 40;
      statusBarHeight = statusBarHeight +30

      this.setData({
        statusBarHeight,
        navBarHeight,
        showBack
      });
    },
    },

  // Component 组件的方法
  methods: {
    
    goBack() {
      wx.navigateBack();
    },
    switchWeek(e){
      const week = e.currentTarget.dataset.week
      this.setData({
        nowWeek:week,       //选择第几周
        showSwitchWeek:false//关闭弹窗
      })
      this.triggerEvent('nowWeek', {
        nowWeek:week
      
      }); //刷新周数数据
    },
    switchWeekButton(){
      this.setData({
        showSwitchWeek:true//打开弹窗
      })
    },
    updateButton(){
      const Switch = true 
      this.triggerEvent('updateButton', Switch); //刷新周数数据
    }
  
    // 可以在这里添加其他方法，如返回首页、触发搜索事件等
  },



})